
import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.AlertType;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.List;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author Mr Bao
 */
public class HomeMain extends List implements CommandListener {

    private UpAnh upAnh;
    private Command cmdExit;
    private Command cmdYes;
    private Command cmdNo;
    private Alert alert;

    public HomeMain(UpAnh upAnh) {
        super("UpAnh", IMPLICIT);
        this.upAnh = upAnh;
        append("Xem anh", null);
        append("Dang anh", null);
        cmdExit = new Command("Exit", Command.EXIT, 2);
        this.addCommand(cmdExit);
        this.setCommandListener(this);
    }

    public void commandAction(Command c, Displayable d) {
        if (c == SELECT_COMMAND) {
            switch (getSelectedIndex()) {
                case 0:
                    upAnh.DisplayViewImage();
                    break;
                case 1:
                    upAnh.DisplayUploadImage();
                    break;
            }
        } else if (c == cmdExit) {
            alert = new Alert("Thoat");
            alert.setType(AlertType.INFO);
            alert.setString("Ban co muon thoat khong?");
            cmdYes = new Command("Co", Command.OK, 2);
            cmdNo = new Command("Khong", Command.BACK, 2);
            alert.addCommand(cmdYes);
            alert.addCommand(cmdNo);
            alert.setCommandListener(this);
            upAnh.display.setCurrent(alert);
        } else if (c == cmdYes){            
            upAnh.Exit();
        } else if (c==cmdNo){
            upAnh.DisplayHomeMain();
        }
    }
}
